export const EMIT_AVATAR_CLICK = "avatar-click"

export const DEFAULT_MENU_LASTMESSAGES = "messages"
export const DEFAULT_MENU_CONTACTS = "contacts"
export const DEFAULT_MENUS = [DEFAULT_MENU_LASTMESSAGES, DEFAULT_MENU_CONTACTS]
/**
 * 聊天消息类型
 * 消息类型：AT("@"), TEXT("文本"), FILE("文件") NOTICE("通知") RECALL("撤回");
 */
export const MESSAGE_TYPE = {
  AT: 1,
  TEXT: 2,
  FILE: 3,
  NOTICE: 4,
  RECALL: 5
}

/**
 * 文件类型：DOC("文档"), PIC("图片"), VIDEO("视频"), VOICE("音频"), OTHER("其它");
 */
export const FILE_TYPE = {
  DOC: 1,
  PIC: 2,
  VIDEO: 3,
  VOICE: 4,
  OTHER: 5
}

// NORMAL("正常"), NOT_IN_GROUP("不在群中"), GROUP_DISSOLUTION("群组已解散");
export const CHAT_STATUS = {
  NORMAL: 1,
  NOT_IN_GROUP: 2,
  GROUP_DISSOLUTION: 3
}

/**
 * 聊天消息状态
 */
export const MESSAGE_STATUS = ["going", "succeed", "failed"]

export const CONTACT_TYPE = ["im/action", "im/simple", "im/group"]

export function getFileType(url) {
  const reg = /\.(.+)$/
  const type = reg.exec(url)[1]
  const fileType = {
    excel: { type: ["xls", "xlsx"], bigType: FILE_TYPE.DOC, color: "#E4F9F3" },
    word: { type: ["doc", "docx"], bigType: FILE_TYPE.DOC, color: "#F2F8FF" },
    pdf: { type: ["pdf"], bigType: FILE_TYPE.DOC },
    image: {
      type: ["png", "jpg", "jpeg", "gif", "bmp"],
      bigType: FILE_TYPE.PIC
    },
    audio: {
      type: ["mp3", "wav", "wma", "ogg", "ape", "flac"],
      bigType: FILE_TYPE.VOICE
    },
    video: {
      type: ["mp4", "avi", "rmvb", "rm", "flv", "mkv", "mov", "3gp"],
      bigType: FILE_TYPE.VIDEO
    },
    ppt: { type: ["ppt", "pptx"], bigType: FILE_TYPE.DOC },
    zip: { type: ["zip", "rar", "7z", "tar", "gz"], bigType: FILE_TYPE.DOC }
  }

  for (const key in fileType) {
    if (fileType[key].type.includes(type)) {
      return { type: fileType[key].bigType, fileType: key }
    }
  }

  return { type: FILE_TYPE.OTHER, fileType: "other" }
}
